<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
require_once INTE_ROOT . 'INotify.php';
require_once DATA_ROOT . 'NotifyData.php';
require_once DEF_ROOT . 'NotifyDef.php';

class BaseNotify implements INotify {

    public static function getInstance() {
        if (self::$instance == null) {
            self::$instance = new BaseNotify();
        }
        return self::$instance;
    }

    protected static $instance = null;

    protected function __construct() {
        
    }

    public function getNotifies($uid) {
        $ret = array('err' => ErrorDef::OK, 'data' => array());
        try {
            $res = NotifyData::getNotify($uid);
            $data = array();
            foreach (NotifyType::$SUPPORT_TYPE as $notifyType)
            {
                $data[$notifyType] = 0;
            }
            
            foreach($res as $notify_data)
            {
                $data[$notify->type] = $notify->num;
            }
            $ret['data'] = $data;
        } catch (Exception $e)
        {
              $err_code = $e->getCode();
            if (empty($err_code)) {
                $ret['err'] = ErrorDef::COMMON_ERROR_SYS;
            } else {
                $ret['err'] = $err_code;
            }
        }
        return $ret;
    }

    public function addNotify($uid, $type) {
        $ret = array('err' => ErrorDef::OK);
        try {
            NotifyData::addNotify($uid_followed, $type);
        } catch (Exception $e) {
            $err_code = $e->getCode();
            if (empty($err_code)) {
                $ret['err'] = ErrorDef::COMMON_ERROR_SYS;
            } else {
                $ret['err'] = $err_code;
            }
        }
        return $ret;
    }

    public function releaseNotify($uid, $type) {
        $ret = array('err' => ErrorDef::OK);
        try {
            NotifyData::releaseNotify($uid_followed, $type);
        } catch (Exception $e) {
            $err_code = $e->getCode();
            if (empty($err_code)) {
                $ret['err'] = ErrorDef::COMMON_ERROR_SYS;
            } else {
                $ret['err'] = $err_code;
            }
            return $ret;
        }
    }

}